#include<iostream>
#include<math.h>
using namespace std;
int main(){
    int n,h,m,s;
    double angleh,anglem,angle;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>h>>m>>s;
        if(h>=12)h-=12;
        angleh=(h+1.0*m/60+1.0*s/3600)*30;
        anglem=(m+1.0*s/60)*6;
        angle=fabs(angleh-anglem);
        if(angle>180)
        cout<<int(360-angle)<<endl;
        else cout<<int(angle)<<endl;
    }
}